package ai;

import player.Player;
import board.Board;
//
///*
// * /*
// ********************************************************
// *  Filename:   AIPlayer.cpp
// ********************************************************
// *  Created on: Nov 5, 2008
// *      Author: marc
// ********************************************************
// 
//
//#include "AIPlayer.h"
//
///* Initializes the player with color and name 
//AIPlayer::AIPlayer(int color, string name, MUTEX* mutex) {
//	m_color = color;
//	m_name = name;
//	m_mutex = mutex;
//	m_heuristic = new Heuristic(this);
//	working = false;
//}
//
//AIPlayer::~AIPlayer() {
//	delete m_heuristic;
//}
//
///* Requests the best move from the Heuristic and makes the move */
//void AIPlayer::makeNextMove(board* b){
//	bool moved=false;
//	working = true;
//	m_mutex->release();
//	while(!moved)
//	{
//		b->calculatePossibleMoves(m_color);					// Moves have to be calculated before moving
//		moved=b->movePiece(m_heuristic->bestMove(b, m_color), m_color);		// TRY
//		b->cleanUndo();
//	}
//	working = false;
//
//}
//
//string AIPlayer::getName() {
//	return m_name;
//}
//
//void AIPlayer::timeoutOccurred() {
//	m_heuristic->timeoutOccured();
//}
//
//

public class AiPlayer implements Player{
	
	private int color;
	private String name;
	private Heuristic heuristic;
	
	public AiPlayer(int color, String name) {
		this.color = color;
		this.name = name;
		this.heuristic = new Heuristic(this);
	}
	
	public int getColor() {
		return color;
	}

	public void setColor(int color) {
		this.color = color;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/* Requests the best move from the Heuristic and makes the move */
	public void makeNextMove(Board b){
		boolean moved = false;
		boolean working = true;
		
		while(moved == false){
			b.calculatePossibleMoves(getColor());					// Moves have to be calculated before moving
			moved = b.movePiece(heuristic.bestMove(b, getColor()), getColor());		// TRY
			b.cleanUndo();
		}
		working = false;

	}
	
}
